<template>
  <div class="order-tab">
    <ul class="order-list">
      <li
        class="order-item"
        :class="{ active: activeIndex === index }"
        v-for="(item, index) in list"
        :key="index"
        @click="liClick(index)"
      >
        {{ item }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: ["全部订单", "待评价", "退款"],
      activeIndex: 0,
    };
  },
  props: {
    tabIndex: {
      type: Number,
      default: 0,
    },
  },
  watch: {
    tabIndex(newVal) {
      this.activeIndex = newVal;
    },
  },
  methods: {
    liClick(index) {
      this.activeIndex = index;
      //将index传给父组件
      this.$emit("tabIndex", index);
      console.log(index);
    },
  },
};
</script>

<style lang="scss" scoped>
.order-tab {
  width: 100%;
  height: 1.146667rem;
  background-color: #fff;
  .order-list {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    text-align: center;
    font-size: 0.4rem;
    color: #666;
    .order-item {
      width: 100%;
      height: 100%;
      line-height: 1.146667rem;
      transition: all 0.3s;
      &.active {
        color: #5e98fb;
        position: relative;
      }
      &.active::after {
        content: "";
        display: block;
        width: 0.533333rem;
        height: 0.053333rem;
        background-color: #5e98fb;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
}
</style>